package demo.java.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

import org.junit.Test;

public class ResourceBundleDemo {

    public static void main(String[] args) {

    }

    /**
     * 通过 java.util.ResourceBundle 类来读取，这种方式比使用 Properties 要方便一些
     * 
     * @throws IOException
     */
    @Test
    public void demo(InputStream inStream) throws IOException {
        // config为属性文件名，放在包com.test.config下，如果是放在src下，直接用config即可
        ResourceBundle resource = ResourceBundle.getBundle("com/test/config/config");
        String key = resource.getString("keyWord");

    }

    static void test() {
        File file = new File("");
        try (InputStream stream = new FileInputStream(file);) {
            PropertyResourceBundle resource2 = new PropertyResourceBundle(stream);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
